import datetime
import time
# import os

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
# from webdriver_manager.chrome import ChromeDriverManager

from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager

#
# os.environ['WDM_SSL_VERIFY'] = '0'
# os.environ['WDM_LOCAL'] = '1'
# os.environ['WDM_PROXY'] = 'https://npm.taobao.org/mirrors/chromedriver'


ChromeIns = ChromeDriverManager().install()

#
# edgeIns=EdgeDriverManager().install()
driver = webdriver.Chrome(service=Service(ChromeIns))
# driver = webdriver.Edge(EdgeChromiumDriverManager().install())
driver.get("https://www.baidu.com")
driver.implicitly_wait(20)
driver.maximize_window()

driver.find_element(By.CSS_SELECTOR,"#kw").send_keys("歼20")

driver.find_element(By.CSS_SELECTOR,"#su").click()
driver.find_element(By.CSS_SELECTOR,"#\\31  > div > h3 > a > div > div > p > span > span").click()

curWindow = driver.current_window_handle
allWindows = driver.window_handles
for window in allWindows:
    if curWindow != window:
        driver.close()
        driver.switch_to.window(window)
curWin = driver.title
print(curWin)

name = "test_jian20-" + datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S") + ".png"
driver.save_screenshot('../img/' + name)

# str = driver.find_element(By.CSS_SELECTOR,"#J-lemma-main-wrapper > div.contentWrapper_k9vAe > div > div.mainContent_TWv4s > div > div.lemmaSummary_yKMC1.J-summary > div:nth-child(2) > span:nth-child(3)").text
str = driver.find_element(By.XPATH,'//*[@id="J-lemma-main-wrapper"]/div[2]/div/div[1]/div/div[7]/div[53]/span[1]').text
print(f"text:{str}")
time.sleep(5)

alert = driver.switch_to.alert

alert.send_keys("woshinidiedie")

driver.close()
time.sleep(2)

driver.quit()